var stock_id1;
var stock_id8;
var stock_id7;
var stock_id6;
var stock_id5;
var stock_id4;
var stock_id3;
var stock_id2;

var local="http://localhost";

function createXMLHttpStock() {
    //使用大部分浏览器
    var xmlHttp;
    if(window.XMLHttpRequest){
        xmlHttp=new XMLHttpRequest();
    }
    if(window.ActiveXObject){
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        if(!xmlHttp){
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
    }
    return xmlHttp;
}
//无参数GET请求
var xmlHttp_stock;
//通过鼠标点击事件创建HTTP请求
function getStock() {

    xmlHttp_stock = createXMLHttpStock();
    var url = local + ":8080/stock/getStockListDESC";//服务器URL
    var txt = "page=0"
    xmlHttp_stock.open("POST", url, true);
    xmlHttp_stock.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp_stock.send(txt);
    //传输结束

    xmlHttp_stock.onreadystatechange = function () {

        var result = xmlHttp_stock.responseText;
        var json = eval("(" + result + ")");
        var input1 = document.getElementsByName("Bid1");
        stock_id1 = json.data.content[0].keyId;
        input1[0].value = json.data.content[0].product_name;
        input1[1].value = json.data.content[0].brand;
        input1[2].value = json.data.content[0].model_code;
        input1[3].value = json.data.content[0].size;
        input1[4].value = json.data.content[0].inventory;
        input1[5].value = json.data.content[0].sale_price.toFixed(2);


        var input2 = document.getElementsByName("Bid2");
        stock_id2 = json.data.content[1].keyId;
        input2[0].value = json.data.content[1].product_name;
        input2[1].value = json.data.content[1].brand;
        input2[2].value = json.data.content[1].model_code;
        input2[3].value = json.data.content[1].size;
        input2[4].value = json.data.content[1].inventory;
        input2[5].value = json.data.content[1].sale_price.toFixed(2);


        var input3 = document.getElementsByName("Bid3");
        stock_id3 = json.data.content[2].keyId;
        input3[0].value = json.data.content[2].product_name;
        input3[1].value = json.data.content[2].brand;
        input3[2].value = json.data.content[2].model_code;
         input3[3].value = json.data.content[2].size;
        input3[4].value = json.data.content[2].inventory;
        input3[5].value = json.data.content[2].sale_price.toFixed(2);


        var input4 = document.getElementsByName("Bid4");
        stock_id4 = json.data.content[3].keyId;
        input4[0].value = json.data.content[3].product_name;
        input4[1].value = json.data.content[3].brand;
        input4[2].value = json.data.content[3].model_code;
        input4[3].value = json.data.content[3].size;
        input4[4].value = json.data.content[3].inventory;
        input4[5].value = json.data.content[3].sale_price.toFixed(2);


        var input5 = document.getElementsByName("Bid5");
        stock_id5 = json.data.content[4].keyId;
        input5[0].value = json.data.content[4].product_name;
        input5[1].value = json.data.content[4].brand;
        input5[2].value = json.data.content[4].model_code;
        input5[3].value = json.data.content[4].size;
        input5[4].value = json.data.content[4].inventory;
        input5[5].value = json.data.content[4].sale_price.toFixed(2);


        var input6 = document.getElementsByName("Bid6");
        stock_id6 = json.data.content[5].keyId;
        input6[0].value = json.data.content[5].product_name;
        input6[1].value = json.data.content[5].brand;
        input6[2].value = json.data.content[5].model_code;
        input6[3].value = json.data.content[5].size;
        input6[4].value = json.data.content[5].inventory;
        input6[5].value = json.data.content[5].sale_price.toFixed(2);


        var input7 = document.getElementsByName("Bid7");
        stock_id7 = json.data.content[6].keyId;
        input7[0].value = json.data.content[6].product_name;
        input7[1].value = json.data.content[6].brand;
        input7[2].value = json.data.content[6].model_code;
        input7[3].value = json.data.content[6].size;
        input7[4].value = json.data.content[6].inventory;
        input7[5].value = json.data.content[6].sale_price.toFixed(2);


        var input8 = document.getElementsByName("Bid8");
        stock_id8 = json.data.content[7].keyId;
        input8[0].value = json.data.content[7].product_name;
        input8[1].value = json.data.content[7].brand;
        input8[2].value = json.data.content[7].model_code;
        input8[3].value = json.data.content[7].size;
        input8[4].value = json.data.content[7].inventory;
        input8[5].value = json.data.content[7].sale_price.toFixed(2);







    }
}


function homeload() {
    getname();
    findDelivery();
    onClickAjax_Resume();
    onClickAjax_bid();
    getStock();
    onClickAjax_reresume();

}



function getname() {
    var user_id=getCookie('userId');
    var xmlHttp=createXMLHttpName();
    var url=local+":8080/login/displayName";//服务器URL

    txt="user_Id="+user_id;

    xmlHttp.open("POST",url,true);


     xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
     xmlHttp.send(txt);
     xmlHttp.onreadystatechange=function()
     {
         if (xmlHttp.readyState==4 && xmlHttp.status==200)
        {
             var result=xmlHttp.responseText;
            var json=eval("("+result+")");
            var msg=json.msg;
            document.getElementById("getname").value=msg;

         }
     }
    function createXMLHttpName() {
        //使用大部分浏览器
        var xmlHttp;
        if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        }
        if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            if (!xmlHttp) {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
        }
        return xmlHttp;


    }
}



function findDelivery() {
    var user_id=getCookie('userId');
    var xmlHttp_delivery=createXMLHttp_delivery();
    var url=local+":8080/delivery/testUser";//服务器URL

    txt="user_id="+user_id;

    xmlHttp_delivery.open("POST",url,true);


    xmlHttp_delivery.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp_delivery.send(txt);
    xmlHttp_delivery.onreadystatechange=function()
    {
        if (xmlHttp_delivery.readyState==4 && xmlHttp_delivery.status==200)
        {
            var result=xmlHttp_delivery.responseText;
            var json=eval("("+result+")");
            var msg=json.msg;
            if(msg=="false"){
            }
        }
    }
    function createXMLHttp_delivery() {
        //使用大部分浏览器
        var xmlHttp;
        if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        }
        if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            if (!xmlHttp) {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
        }
        return xmlHttp;


    }
}